package cameratricks;


import java.awt.Rectangle;

import processing.core.PApplet;
import processing.core.PImage;
import processing.video.Capture;
import hypermedia.video.OpenCV;

public class FaceWack implements Renderer {
	Capture capture;
	PApplet p;
	
	public FaceWack(TrickCarousel p) {
		this.capture = p.getCapture();
		this.p = p;
	}

	public void draw(OpenCV opencv) {
		Rectangle[] faces = opencv.detect(2F, 1, OpenCV.HAAR_DO_ROUGH_SEARCH, 50,50);
	    
		PImage image = opencv.image();
		p.image(image, 0, 0);
		System.out.println(faces.length);
	    // draw detected face area(s)
	    p.noFill();
	    p.stroke(255,0,0);
	    for( int i=0; i<faces.length; i++ ) {
	        PImage faceImg = image.get( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
	        
	        faceImg.filter(p.INVERT);
	        faceImg.filter(p.POSTERIZE, 4);

	        p.image(faceImg, faces[i].x, faces[i].y);
	        // do some distortion of your face!!!
	        
	        
//	        p.rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height );
	        
	    }

	}
	
	


}
